
PdependsOnH()
FUNCTION PdependsOnH()
SYSTEM(BackGround=995, FontSize=16)
DO height = 250, 10000, 250 ! height from 250m to 10000m in 250m steps
idx = height/250
$HeiPres(idx, 1) = height
$HeiPres(idx, 2) = BarometricPressure(height)
ENDDO
F2()
F3()
F4()
END
FUNCTION BarometricPressure(h)
a = 0.0065 ! K/m
T0 = 15 + 273 ! K
M = 0.02896 ! kg/mol
g = 9.81 ! m/s2
R = 8.314 ! J/K/mol = kg*m/s2 /K/mol
P0 = 1013 ! hPa = h N/m2 = h m*kg/s2 /m2
BarometricPressure = P0 * ((1 - a*h/T0) ^ (M*g/R/a))
END
FUNCTION F2() ! standard loop graph demonstrates single step plotting
DLG(R=2,C=4,BackG=99, AXis=3, X=1,MAX=8000,TIt='1 LINE call / data point', Y=1,MIN=300,MAX=1000,TI='pressure/hPa')
DO height = 250, 8000, 250
pressure = BarometricPressure(height)
LINE(AX=3, X=height, Y=pressure, Symbol='○', Width=3, Draw=-900)
ENDDO
END
FUNCTION F3() ! internal $ loop variable, depends on matrix $HeiPres(height, pressure)
DLG(R=2,C=4,BackG=990, AXis=4, X=1,MAX=8000,TIt='1 call for full matrix', Y=1,TI='pressure/hPa',MIN=300,MAX=1000)
LINE(AX=4, Col=1,XVec=$HeiPres, Col=2,YVec=$HeiPres, Symbol='○', Draw=-9)
END
FUNCTION F4() ! show p(h) array and explain
DLG(R=2,C=4, Nr=8, TItle='height and pressure', Array=$HeiPres, Ti='nr,height/m,pressure/hPa')
DLG(B='OK, show script', B='Quit HicEst', XEQ='SYSTEM(QUIT=1)', E='#Explain')
IF($txtRC=='OK, show script')
DLG(Kill=3, Kill=4, Kill=8)
ELSEIF($txtRC == "Quit HicEst")
SYSTEM(Quit=1)
END
ENDIF
END
#Explain
We calculate the atmospheric pressure as a function of altitude
You need to know:
. Line 1 is always executed at start.
. A FUNCTION call auto-runs the script.
. This script starts with FUNCTION PdependsOnH()
. To see the code: hit ESCAPE
. All 4 windows are modeless: code does not wait for closure
. NR=.. or AX=.. assign the numbers for modeless windows
A matrix $HeiPres with 81 rows and 2 columns is built
. A matrix column can be either numeric or text
Functions return a value with the RETURN ... statement
Useful to know:
. Rows=r and Cols=c divide the screen in r*c areas
. Nr=wdwNr or AX=axNr will be within this screen area.
. Press F1 over an item to show its value.
. Vectors and matrices are edited with the DLG function.
. Define FUNCTIONs should be at the end of the code.
###